//
//  HNSH_AgentBottomView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/8/26.
//

#import "HNSH_AgentBottomView.h"

@interface HNSH_AgentBottomItemView : UIView

/* leftLabel */
@property (nonatomic, strong) UILabel *leftLabel;
/* rightLabel */
@property (nonatomic, strong) UILabel *rightLabel;
/* iconImgV */
@property (nonatomic, strong) UIImageView *iconImgV;

@end

@implementation HNSH_AgentBottomItemView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addSubview:self.leftLabel];
    [self addSubview:self.rightLabel];
    [self addSubview:self.iconImgV];
    
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.equalTo(self.mas_centerY);
        make.height.mas_equalTo(17);
    }];
    
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.equalTo(self.mas_centerY);
        make.height.mas_equalTo(17);
    }];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.rightLabel.mas_left).offset(-4);
        make.centerY.equalTo(self.mas_centerY);
        make.width.height.mas_equalTo(16);
    }];
}

#pragma mark lazy
- (UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc]init];
        _leftLabel.textColor = [UIColor appGray666LabelColor];
        _leftLabel.font = [UIFont systemFontOfSize:12];
    }
    return _leftLabel;
}

- (UILabel *)rightLabel {
    if (!_rightLabel) {
        _rightLabel = [[UILabel alloc]init];
        _rightLabel.textColor = [UIColor colorWithHexString:@"#50AC2D"];
        _rightLabel.font = [UIFont systemFontOfSize:12];
    }
    return _rightLabel;
}

- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        _iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_agent_bottom_lsnl_icon"]];
    }
    return _iconImgV;
}

@end

@interface HNSH_AgentBottomView ()

/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation HNSH_AgentBottomView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#FFF9F5"];
        [self configUI];
        
        [self loadAgentConfig];
    }
    return self;
}

- (void)loadAgentConfig {
    [HNSH_UserNetServer requestAgentConfigSuccess:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            NSArray *array = responseObject.resultset[@"price_list"];
            for (int i = 0; i < array.count; i ++) {
                NSDictionary *dict = array[i];
                HNSH_AgentBottomItemView *item = [[HNSH_AgentBottomItemView alloc]initWithFrame:CGRectMake(0, 38+23*i, self.width, 23)];
                item.leftLabel.text = dict[@"left_text"];
                item.rightLabel.text = dict[@"right_text"];
                [self addSubview:item];
            }
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

- (void)configUI {
    [self addSubview:self.titleLabel];
}

#pragma mark lazy
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(12, 12, 200, 20)];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _titleLabel.text = @"开通条件";
    }
    return _titleLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
